package com.xinjiang.electricpower.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.xinjiang.electricpower.domain.DTO.WorkOrderPoolDTO;
import com.xinjiang.electricpower.domain.vo.*;
import com.xinjiang.electricpower.service.IWorkOrderMonitorService;
import com.xinjiang.electricpower.service.IWorkOrderPoolService;
import com.xinjiang.electricpower.service.IXjOrderGeneralService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author feizhao
 * @date 2022/11/11
 * @apiNote 工单池控制层
 */
@RestController
@RequestMapping("/xinjiang-power-supply-station/work-order-pool/")
@Api(value = "工单中心-工单池", tags = "工单中心-工单池")
//@Validated//有此注解，才会校验游离的参数
@Slf4j
@RequiredArgsConstructor
public class WorkOrderPoolController extends BaseController {

    private final IWorkOrderPoolService workOrderPoolService;
    private final IWorkOrderMonitorService workOrderMonitorService;

    private final IXjOrderGeneralService xjOrderGeneralService;

    /**
     * @param workOrderPoolDTO 工单池DTO类
     * @return List<WorkOrderStatisticsStatusVO> 工单占比状态
     * @description 工单池工单占比状态
     */
    @GetMapping("/work-order-status-statistics")
    @ApiOperation(value = "工单池-工单占比状态", notes = "工单池-工单占比状态")
    public R<List<WorkOrderStatisticsStatusVO>> getWorkOrderPoolSummaryNum(WorkOrderPoolDTO workOrderPoolDTO) {
        List<WorkOrderStatisticsStatusVO> items = workOrderMonitorService.getNumsByStatusTest(workOrderPoolDTO);
        return R.ok(items, "查询成功");
    }

    /**
     * @param workOrderPoolDTO 工单池DTO类
     * @return List<WorkOrderStatisticsStatusVO> 台区工单统计
     * @description 台区工单统计
     */
    @GetMapping("/tg-work-order-statistics")
    @ApiOperation(value = "统计指定年月各个台区的工单数", notes = "统计指定年月各个台区的工单数")
    public R<List<TgWorkOrderStatisticVO>> getTgWorkOrderNum(WorkOrderPoolDTO workOrderPoolDTO) {
        List<TgWorkOrderStatisticVO> items = xjOrderGeneralService.selectXjOrderGeneralsTest(workOrderPoolDTO);
        return R.ok(items, "查询成功");
    }


    @GetMapping("/count-system-orders")
    @ApiOperation(value = "工单池工单业务占比", notes = "工单池工单业务占比")
    public R<List<SystemOrdersVO>> getSystemOrderNum(WorkOrderPoolDTO workOrderPoolDTO) {
        return R.ok(xjOrderGeneralService.countSystemOrdersTest(workOrderPoolDTO), "查询成功");
    }

    /**
     * @param workOrderPoolDTO 工单池DTO类 -------不用变更
     * @return List<EventProcessingVO> 工单总数
     * @description 统计指定年月各个预警类型的工单数
     */
    @GetMapping("/work-order-priority-statistics")
    @ApiOperation(value = "统计指定年月各个预警类型的工单数", notes = "统计指定年月各个预警类型的工单数")
    public R<List<WarningUrgentVO>> getWorkOrderWarningNum(WorkOrderPoolDTO workOrderPoolDTO) {
        List<WarningUrgentVO> items = xjOrderGeneralService.selectWorkOrderWarning(workOrderPoolDTO);
        return R.ok(items, "查询成功");
    }

    /**
     * @param workOrderPoolDTO 工单池DTO类
     * @return List<SystemOrdersVO> 工单总数
     * @description 统计指定年月各个系统/业务的工单数
     */
    @GetMapping("/work-order-system-statistics")
    @ApiOperation(value = "统计指定年月各个系统/业务的工单数", notes = "统计指定年月各个系统/业务的工单数")
    public R<List<SystemOrdersVO>> getWorkOrderSystemNum(WorkOrderPoolDTO workOrderPoolDTO) {
        List<SystemOrdersVO> items = xjOrderGeneralService.selectWorkOrderSystemTest(workOrderPoolDTO);
        return R.ok(items, "查询成功");
    }

    /**
     * @param workOrderPoolDTO 工单池DTO类
     * @return List<WorkOrderNatureStatisticVO> 工单总数
     * @description 统计指定年月各个工单性质的工单数
     */
    @GetMapping("/work-order-nature-statistics")
    @ApiOperation(value = "统计指定年月各个工单性质的工单数", notes = "统计指定年月各个工单性质的工单数")
    public R<List<WorkOrderNatureStatisticVO>> getWorkOrderNatureNum(WorkOrderPoolDTO workOrderPoolDTO) {
        List<WorkOrderNatureStatisticVO> items = xjOrderGeneralService.selectWorkOrderNature(workOrderPoolDTO);
        return R.ok(items, "查询成功");
    }

    /**
     * @param workOrderPoolDTO 工单池实体类
     * @return R<Long> 工单总数
     * @description 工单池按照各个类型汇总待办工单
     */
    @GetMapping("/count")
    @ApiOperation(value = "工单池按照各个类型汇总待办工单", notes = "工单池按照各个类型汇总待办工单")
    public R<List<WorkOrderPoolSummaryVO>> getWorkOrderPoolSummaryNum1(WorkOrderPoolDTO workOrderPoolDTO) {
        List<WorkOrderPoolSummaryVO> items = workOrderPoolService.getXjOrderGeneralByStatus(workOrderPoolDTO);
        return R.ok(items, "查询成功");
    }

    /**
     * @param workOrderPoolDTO 工单实体类
     * @param page             分页对象
     * @return R<IPage < WorkOrderPoolVO>> 工单池-归类统计工单分页列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询工单池-归类统计工单", notes = "查询工单池-归类统计工单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "workOrderPoolDTO", value = "工单池DTO实体类", paramType = "query", dataType = "WorkOrderPoolDTO", dataTypeClass = com.xinjiang.electricpower.domain.DTO.WorkOrderPoolDTO.class),
            @ApiImplicitParam(name = "page", value = "分页对象", paramType = "query", dataType = "PageDTO<XjOrderGeneralVO>", dataTypeClass = com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO.class)
    })
    public R<PageInfo<WorkOrderPoolVO>> getXjOrderGeneralProcess(WorkOrderPoolDTO workOrderPoolDTO, PageDTO<WorkOrderPoolVO> page) {
        PageInfo<WorkOrderPoolVO> pages = xjOrderGeneralService.selectXjOrdralPoolPerGeneageTest(page, workOrderPoolDTO);
        return R.ok(pages, "查询成功");
    }

    /**
     * 导出待处理、已完成、处理中的工单
     */
    @ApiOperation("导出工单池的工单")
    @Log(title = "导出工单池的工单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "workOrderPoolDTO", value = "workOrderPoolDTO类的ids属性", required = true, paramType = "body", dataType = "WorkOrderPoolDTO", dataTypeClass = com.xinjiang.electricpower.domain.DTO.WorkOrderPoolDTO.class),
            @ApiImplicitParam(name = "response", value = "响应流", dataType = "HttpServletResponse", dataTypeClass = javax.servlet.http.HttpServletResponse.class)
    })
    public void export(HttpServletResponse response, @RequestBody WorkOrderPoolDTO workOrderPoolDTO) {
        List<WorkOrderPoolVO> list = xjOrderGeneralService.selectWorkOrderPools(workOrderPoolDTO.getIds());
        ExcelUtil<WorkOrderPoolVO> util = new ExcelUtil<WorkOrderPoolVO>(WorkOrderPoolVO.class);
        util.exportExcel(response, list, "导出工单池的工单");
    }

    /**
     *
     */
    @ApiOperation("导出工单池的工单，全导出或条件查询导出")
    @Log(title = "导出工单池的工单，全导出或条件查询导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exports")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "workOrderPoolDTO", value = "workOrderPoolDTO实体类", paramType = "body", dataType = "WorkOrderPoolDTO", dataTypeClass = com.xinjiang.electricpower.domain.DTO.WorkOrderPoolDTO.class),
            @ApiImplicitParam(name = "response", value = "响应流", dataType = "HttpServletResponse", dataTypeClass = javax.servlet.http.HttpServletResponse.class)
    })
    public void exports(HttpServletResponse response, @RequestBody WorkOrderPoolDTO workOrderPoolDTO) {

        List<WorkOrderPoolVO> list = xjOrderGeneralService.selectWorkOrderPools(workOrderPoolDTO);
        ExcelUtil<WorkOrderPoolVO> util = new ExcelUtil<WorkOrderPoolVO>(WorkOrderPoolVO.class);
        util.exportExcel(response, list, "导出工单池的工单，全导出或条件查询导出");
    }
}
